package com.app.micaihu.view.main.dialog.adapter

import android.widget.ImageView
import android.widget.TextView
import com.app.micaihu.R
import com.app.micaihu.view.bean.Military
import com.app.micaihu.view.utils.loadImage
import com.app.micaihu.view.utils.loadImageNoScaleType
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class MilitaryAdapter : BaseQuickAdapter<Military, BaseViewHolder>(R.layout.military_list_item) {

    override fun convert(holder: BaseViewHolder, item: Military) {

        val tvTitle = holder.getView<TextView>(R.id.tvTitle)
        tvTitle.text = item.name
        val imageView = holder.getView<ImageView>(R.id.ivImage)
        imageView.loadImageNoScaleType(item.icon)
        if (item.check) {
            imageView.alpha = 1.0F
            tvTitle.alpha = 1.0F
        } else {
            imageView.alpha = 0.5F
            tvTitle.alpha = 0.5F
        }
    }

    fun setCheck(position: Int) {
        for ((index, item) in data.withIndex()) {
            item.check = index == position
        }
        notifyDataSetChanged()
    }

}